package com.h3c.gm.schedule

import com.h3c.gm.common.constant.HostOrgkeyPair
import com.h3c.gm.schedule.task.HostTask
import com.h3c.gm.schedule.task.QuotaTask
import com.h3c.gm.schedule.task.StorageStatusTask
import com.h3c.gm.schedule.task.StorageTask
import com.h3c.gm.schedule.task.UserTask
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component

import javax.annotation.Resource
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit

/**
 * Created by d14287 on 2017/7/7.
 */
@Component
class Scheduler {
    static Logger logger = LoggerFactory.getLogger(Scheduler.class)
    static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2)

    static {
        HostOrgkeyPair.values().each {
            hostOrgkeyPair ->
                //分别与1分钟/5分钟/10分钟/15分钟/20分钟后开始第一次执行，执行周期间隔为一天
                /**
                 scheduledExecutorService.scheduleAtFixedRate(new HostTask(hostOrgkeyPair), 60 * 1, 24 * 60 * 60, TimeUnit.SECONDS)
                 scheduledExecutorService.scheduleAtFixedRate(new UserTask(hostOrgkeyPair), 60 * 5, 24 * 60 * 60, TimeUnit.SECONDS)
                 scheduledExecutorService.scheduleAtFixedRate(new StorageTask(hostOrgkeyPair), 60 * 10, 24 * 60 * 60, TimeUnit.SECONDS)
                 scheduledExecutorService.scheduleAtFixedRate(new QuotaTask(hostOrgkeyPair), 60 * 15, 24 * 60 * 60, TimeUnit.SECONDS)
                 scheduledExecutorService.scheduleAtFixedRate(new StorageStatusTask(hostOrgkeyPair), 60 * 20, 24 * 60 * 60, TimeUnit.SECONDS)
                 */
                //测试环境
                /**
                scheduledExecutorService.scheduleAtFixedRate(new HostTask(hostOrgkeyPair), 5, 24 * 60 * 60, TimeUnit.SECONDS)
                scheduledExecutorService.scheduleAtFixedRate(new UserTask(hostOrgkeyPair), 5, 24 * 60 * 60, TimeUnit.SECONDS)
                scheduledExecutorService.scheduleAtFixedRate(new StorageTask(hostOrgkeyPair), 5, 24 * 60 * 60, TimeUnit.SECONDS)
                scheduledExecutorService.scheduleAtFixedRate(new QuotaTask(hostOrgkeyPair), 5, 24 * 60 * 60, TimeUnit.SECONDS)
                scheduledExecutorService.scheduleAtFixedRate(new StorageStatusTask(hostOrgkeyPair), 5, 24 * 60 * 60, TimeUnit.SECONDS)
                */
        }
    }
}